(function () {

	var loaded = false,
		scriptLoad = function () {
		
			if (loaded) return;
		
			loaded = true;
			
			function createElement(onMove) {
				var el = document.createElement("div"),
					pos = {x:0, y:0};
				el.style.cssText = "width:200px;height:200px;position:absolute;z-index:9999;border:1px solid black;";
				document.body.appendChild(el);
				var prev = pos,
					track = false,
					move = function (e) {
						var cx = e.pageX || 0,
							cy = e.pageY || 0;
						pos.x += (cx - prev.x);
						pos.y += (cy - prev.y);
						el.style.top = pos.y + "px";
						el.style.left = pos.x + "px";
						prev = {x: cx, y: cy};
						onMove();
					};
				move(pos);
				document.addEventListener("mousedown", function (e) {
					if (e.target !== el) return;
					track = true;
					e.preventDefault();
					prev = {x: e.pageX, y: e.pageY};
				});

				document.addEventListener("mouseup", function (e) {
					track = false;
				});

				document.addEventListener("mousemove", function (e) {
					track && move(e);
				});
				return el;
			};

			var div = createElement(function () {
				instance && instance.updatePosition();
			});
			
			console.time("Aero");
			var instance = new Aero(div, {ready: function () {
								console.timeEnd("Aero");
						   }});
			
		};
		
	if (!confirm("Create window?")) {
		scriptLoad = function () {
			console.time("Aero");
			Aero.ScreenShot(document, function () {
				console.timeEnd("Aero");
				if (confirm("Screenshot?")) {
					this.style.cssText = "position:absolute;top:0;left:0;z-index:9999;";
					document.body.appendChild(this);
					var img = this,
						slider = document.createElement("input");
					slider.type = "range";
					slider.min = 0;
					slider.max = 100;
					slider.value = 100;
					slider.style.cssText = this.style.cssText;
					slider.onchange = function () {img.style.opacity = this.value / 100;}
					document.body.appendChild(slider);
				} else {
					var code = this.src.replace(/^.*?,/, ""),
						div = document.createElement("div");
					code = decodeURIComponent(escape(atob(code)));
					div.innerHTML = code;
					console.log(div.firstChild);
				}
			});
		};
	}
	
	if (!window.Aero) {
		var script = document.createElement("script");
		script.onload = script.onreadystatechange = scriptLoad;
		script.type = "text/javascript";
		script.src = "//aerojs.googlecode.com/svn/trunk/Aero.js";
		document.body.appendChild(script);
	} else {
		scriptLoad();
	}
	
})();